<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Basic JSON Editor Example</title>
    <script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
  </head>
  <body>
    <h1>UUID JSON Editor Example</h1>
    
    <div id='editor_holder'></div>
    <button id='submit'>Submit (console.log)</button>

    <script>
      JSONEditor.defaults.options['required_by_default'] = true;
      // Initialize the editor with a JSON schema
      var editor = new JSONEditor(document.getElementById('editor_holder'),{
        schema: {
          "type": "object",
          "title": "UUID format with autogenerated uuid",
          "properties": {
            "_header": {
              "type": "string",
              "format": "hidden",
              "description": "Example of new editor format [uuid] for string type. Value must be a valid RFC 4122 uuid (Universally Unique IDentifier). If field has initial no value (startval) then a random uuid will be autogenerated",
              "options": {
                "compact": true
              }
            },
            "uuid1": {
              "type": "string",
              "format": "uuid",
              "description": "uuid field with value in startval (Value should be: dd4f33f9-46f4-46b0-8143-5d75a7eea115)"
            },
            "uuid1-clone": {
              "type": "string",
              "description": "watching uuid field with value in startval",
              "template": "{{uuid}}",
              "watch": {
                "uuid": "uuid1"
              }
            },
            "uuid2": {
              "type": "string",
              "format": "uuid",
              "description": "uuid field with no value in startval (autogenerated)"
            },
            "uuid2-clone": {
              "type": "string",
              "description": "watching uuid field with no value in startval",
              "template": "{{uuid}}",
              "watch": {
                "uuid": "uuid2"
              }
            }
          }
        },
        startval: {
          "uuid1": "dd4f33f9-46f4-46b0-8143-5d75a7eea115"
        }
      });

      // Hook up the submit button to log to the console
      document.getElementById('submit').addEventListener('click',function() {
        // Get the value from the editor
        console.log(editor.getValue());
      });
    </script>
  </body>
</html>
